/*
 *  Copyright 2002 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *
 */
/* "@(#) RF5_IEK 1.20.07 09-26-02 (swat-c12)" */
/*
 *  ======== celljpegenc.c ========
 */

#include <std.h>

#include <log.h>
#include <tsk.h>

#include <algrf.h>
#include <icell.h>
#include <utl.h>

#include "celljpegenc_ti.h"
#include "ijpegenc.h"

#include <dman.h>

#include "appThreads.h"
#include "appBiosObjects.h"

extern far IDMA2_Fxns JPEGENC_IDMA2;        /* the algorithm's IDMA2 v-table */

// v-table for this cell
ICELL_Fxns JPEGENC_CELLFXNS = {
    JPEGENC_cellClose,     // cellClose
    JPEGENC_cellControl,   // cellControl
    JPEGENC_cellExecute,   // cellExecute
    JPEGENC_cellOpen       // cellOpen
};

/*
 *  ======== JPEGENC_cellClose ========
 *
 */
Bool JPEGENC_cellClose( ICELL_Handle handle )
{
    // Withdraw DMA resources from algorithm
    return (DMAN_removeAlg((IALG_Handle)handle->algHandle, &JPEGENC_IDMA2));

}

/*
 *  ======== JPEGENC_cellExecute ========
 *
 */
Bool JPEGENC_cellExecute( ICELL_Handle handle, Arg arg )
{
    int ret_val ;
    unsigned int **Output = handle->outputIcc[0]->buffer;

    UTL_stsStart( stsExeTimeChJpegEnc );

    // activate instance object
    ALGRF_activate( handle->algHandle );

    // call JPEG encode through ALG layer.
    ret_val = ((IJPEGENC_Fxns *)(handle->algFxns))->encode
                      (
                         (IJPEGENC_Handle)handle->algHandle,
                         (XDAS_Int8 **)handle->inputIcc[0]->buffer,
                         (XDAS_Int8 *)(Output[1])
                      );

    *(Output[0]) = ret_val;

    // deactivate instance object
    ALGRF_deactivate( handle->algHandle );

    UTL_stsStop( stsExeTimeChJpegEnc);

    return (TRUE);
}

/*
 *  ======== JPEGDEC_cellOpen ========
 *
 */
Bool JPEGENC_cellOpen( ICELL_Handle handle )
{
    // Grant DMA resources
    #if 1
    return (DMAN_addAlg((IALG_Handle)handle->algHandle, &JPEGENC_IDMA2));
    #endif
}


/*
 *  ======== JPEGDEC_cellControl ========
 *
 */
Int JPEGENC_cellControl(ICELL_Handle handle, IALG_Cmd cmd, IALG_Status *status)
{

   Bool value;

   value = JPEGENC_TI_control
           (
               (IJPEGENC_Handle) handle->algHandle,
               (IJPEG_Cmd)       cmd,
               (IJPEGENC_Status *) status
           );

   return (value);

}

/*------------------------------------------------------------------*/
/* Texas Instruments Incorporated 1997-2003.                        */
/*==================================================================*/
/*                                                                  */
/*------------------------------------------------------------------*/


